package cuiyt.leetcode.other;

/**
 * @author cyt
 * @create 2020-07-28 14:09
 */
public class T104 {
    /**
     * 递归求出二叉树的左右子树的深度， 每次递归更新答案（左右子树深度中最大值）。
     * @param args
     */
    public static void main(String[] args) {

    }
    public int maxDepth(TreeNode root) {
        int ans = dfs(root, 0);
        System.out.println(ans);
        return ans;
    }
    public int dfs(TreeNode root,int depth) {
        if(root==null) {
            return  0;
        }
        if(root.left==null && root.right==null){
            return depth + 1;
        }
        int left = dfs(root.left,depth+ 1);
        int right = dfs(root.right, depth+1);
        return Math.max(left,right);
    }
}

class TreeNode104 {
     int val;
    TreeNode104 left;
    TreeNode104 right;
    TreeNode104(int x) { val = x; }
 }
